<template>
  <a-spin tip="登录中..." class="w-full h-full flex items-center justify-center flex-col" />
</template>

<script setup>
import { onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { message } from 'ant-design-vue'
import { post } from '@/utils/request'
import useAppStore from '@/store/app'

const router = useRouter()
const href = new URL(window.location.href)
// const token = href.searchParams.get('token')
const url = href.searchParams.get('url')
const appStore = useAppStore()
const onFinish = async () => {
  const { code, data, msg } = await post('/login/doLogin', {
    empId: 'zhnk001',
    pwd: 'zhnk001'
  })
  if (code === 0) {
    message.success('登录成功')
    await appStore.login(data, '', false)
    appStore.CURRENT_ROUTE_NAME = '眼科手术'
    await appStore.addRouter(false)
    router.push({ path: url })
  } else {
    message.error(msg || '登录失败')
  }
}
onMounted(() => {
  onFinish()
})
</script>

<style lang="less" scoped></style>
